package com.bing.common.util;


import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 类型转换器
 *
 * @author ruoyi
 */
public class Convert
{
    public static boolean isPrimitive(Object obj) {
        Class<?> clazz = obj.getClass();
        return clazz.isPrimitive() ||
                clazz.equals(Integer.class) ||
                clazz.equals(Long.class) ||
                clazz.equals(Float.class) ||
                clazz.equals(Double.class) ||
                clazz.equals(Boolean.class) ||
                clazz.equals(Character.class) ||
                clazz.equals(Byte.class) ||
                clazz.equals(Short.class)||
                clazz.equals(String.class);
    }

    /**
     * 集合转id集合
     * @param list
     * @param attr
     * @return
     * @param <T>
     */
    public static  <T,E> List<E> mapIds(List<T> list, Function<? super T,E> attr){
        return list.stream().map(attr).distinct().collect(Collectors.toList());
    }
}
